import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  // This widget is the root of your application.
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Button',
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      home: MyStatelessWidget(),
    );
  }
}

class MyStatelessWidget extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    //定义文本样式

    return Scaffold(
      appBar: AppBar(
        title: Text("Button"),
      ),
      body: Column(
        children: <Widget>[
          new SwitchAndCheckboxComponent()
        ],
      ),
    );
  }

}
class SwitchAndCheckboxComponent extends StatefulWidget{
  @override
  State<StatefulWidget> createState() {
    return _SwitchAndCheckboxComponent();
  }

}

class _SwitchAndCheckboxComponent extends State<SwitchAndCheckboxComponent>{
  var _switchVal = false;
  var _checkBoxVal = false;
  @override
  Widget build(BuildContext context) {
    print(_switchVal);
    print(_checkBoxVal);
    return new Column(
      children: <Widget>[
        Switch(
            value: _switchVal,
            onChanged: (val){
              setState(() {
                this._switchVal = val;
              });
            }
        ),
        Checkbox(
            value: _checkBoxVal,
            onChanged: (val){
              setState(() {
                this._checkBoxVal = val;
              });
            }
        )
      ],
    );
  }

}